# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=eventlet
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.33.3
pkgrel=2
pkgdesc="Highly concurrent networking library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://eventlet.net/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-greenlet"
         "${MINGW_PACKAGE_PREFIX}-python-monotonic"
         "${MINGW_PACKAGE_PREFIX}-python-dnspython"
         "${MINGW_PACKAGE_PREFIX}-python-six")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2: non-blocking PostgreSQL support"
            "${MINGW_PACKAGE_PREFIX}-python-pyopenssl: non-blocking SSL support"
            "${MINGW_PACKAGE_PREFIX}-python-httplib2: non-blocking HTTP support"
            "${MINGW_PACKAGE_PREFIX}-python-pyzmq: non-blocking ZeroMQ support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2"
              "${MINGW_PACKAGE_PREFIX}-python-nose"
              "${MINGW_PACKAGE_PREFIX}-python-pyopenssl"
              "${MINGW_PACKAGE_PREFIX}-python-httplib2"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pyzmq")
options=('staticlibs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/eventlet/eventlet/archive/v${pkgver}.tar.gz)
sha512sums=('b2e1818c7b6134be4020d2b4315bbb3db795960df76da08a490e0d952549eafb477800c884e7a99493146c1ac082aed5fb87c7e2882ee468ea42b5cc26b8517f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  sed -r 's|(check_idle_cpu_usage\(.*,) .*\)|\1 0.8\)|g' \
      -i tests/*_test.py

  cd "${srcdir}"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build 
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/nosetests -sv tests || warning "tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
